package TestDateSort;

public class TestDateSort {
	public static void main(String[] args) {
		Date[] a = new Date[5];
		a[0] = new Date(2006,6,1);
		a[1] = new Date(2007,6,1);
		a[2] = new Date(2006,5,1);
		a[3] = new Date(2006,7,1);
		a[4] = new Date(2004,6,1);
		
		sort(a);
		
		for(int i=0;i<a.length;i++) {
			System.out.println(a[i]);
		}
	}
	
	public static void sort(Date[] a) {
		int length=a.length,i,j;
		for(i=length;i>0;i--){
			for(j=0;j<i-1;j++) {
				if(a[j].compare(a[j+1])>0) {
					Date temp=a[j];
					a[j]=a[j+1];
					a[j+1]=temp;
				}
			}
		}
	}
}
class Date {
	int year,month,day;
	
	Date (int year,int month,int day) {
		this.year=year;
		this.month=month;
		this.day=day;
	}
	
	public int compare(Date a) {
		return this.year>a.year?1:this.year<a.year?-1:this.month>a.month?1:this.month<a.month?-1:this.day>a.day?1:this.day<a.day?-1:0;
	}
	
	public String toString() {
		return "YYYY:MM:DD  "+this.year+":"+this.month+":"+this.day;
	}
}